package com.zhang.second.day02;

import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;

/**
 * @title: 物理分区算子
 * @author: zhang
 * @date: 2022/1/30 09:31
 */
public class Example8 {
    public static void main(String[] args) throws Exception {
        StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();
        env.setParallelism(1);

        env
                .fromElements(1, 2, 3, 4).setParallelism(1)
                .broadcast()
                .print("广播变量：").setParallelism(4);

        env
                .fromElements(1, 2, 3, 4).setParallelism(1)
                .shuffle()
                .print("随机发送：");

        //使用轮询平均分配到下游插槽
        env
                .fromElements(1, 2, 3, 4).setParallelism(1)
                .rebalance()
                .print("轮询平均发送：");

        //将所有数据分送到下游算子的第一个任务插槽
        env
                .fromElements(1, 2, 3, 4).setParallelism(1)
                .global()
                .print("global:").setParallelism(2);

        env.execute();
    }
}
